﻿using System.Windows;
using Ops.Mpc.Presenters;

namespace Ops.Mpc.States
{
    public class ChildPresenterStateAction : StateAction
    {
        #region Fields & Properties

        public static readonly DependencyProperty ChildPresenterNameProperty = DependencyProperty.Register("ChildPresenterName", typeof(string), typeof(ChildPresenterStateAction), null);
        public string ChildPresenterName
        {
            get
            {
                return (string)this.GetValue(ChildPresenterNameProperty);
            }

            set
            {
                this.SetValue(ChildPresenterNameProperty, value);
            }
        }

        #endregion

        #region Methods
        protected override void OnExecute(object context)
        {
            base.OnExecute(context);
            this.Finish();
        }


        protected override void MoveToNextState()
        {
            if (this.Controller != null && !string.IsNullOrEmpty(this.ChildPresenterName) && !string.IsNullOrEmpty(this.NextStateItemName))
            {
                Presenter presenter = this.Controller.Presenter.GetCurrentStateTemplateChild(this.ChildPresenterName) as Presenter;

                if (presenter != null && presenter.Controller != null )
                    presenter.Controller.SetCurrentState(this.NextStateItemName);
            }
        }
        #endregion
    }
}
